/**
 * 
 */
package com.swd2010.mobileSearch.network;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import com.swd2010.mobileSearch.data.internalTransfer.ApplicationDataTransfer;

import android.util.Log;

/**
 * @author haui
 *
 */
public class ConnectInformation {

	
	//You dirty, bloody, idiotic sons of bitches!!!
	//Why don't you reinvent IP, HTTP or something else like that?
	//Because of android devices own router the local host has the ip address 10.0.2.2 and NOT 127.0.0.1
	private String baseUrl = new String( ApplicationDataTransfer.getInstance().getBaseUrl() + "SearchServer/REST/search/"); 
	
	
	private static String personAutoCompleteUrlFragment = new String("PersonAutocomplete");
	
	
	private static String personByIdUrlFragment = new String("PersonById");	
	
	
	private static String personSearchUrlFragment = new String("Persons");
	
	
	
	private static int    autoCompleteNumResults  =  3;
	
	
	
	
	public URL getPersonAutoCompleteUrl(String  searchTerm){
		

		try {
					
			
			return new URL( baseUrl + personAutoCompleteUrlFragment + "?" + "searchTerm=" + URLEncoder.encode(searchTerm, "utf-8") + "&" + "numResults=" + autoCompleteNumResults );

			
		} catch (MalformedURLException e) {			
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} catch (UnsupportedEncodingException e) {
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} 
		
		
		return null;
		
		
	}
	
	
	
	public URL getPersonSearchUrl(String  searchTerm){
		

		try {
					
			
			return new URL( baseUrl + personSearchUrlFragment + "?" + "searchTerm=" + URLEncoder.encode(searchTerm, "utf-8") + "&" + "numResults=120");

			
		} catch (MalformedURLException e) {			
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} catch (UnsupportedEncodingException e) {
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} 
		
		
		return null;
		
		
	}	
	
	
	
	public URL getSinglePersonById(String  id){
		

		try {
					
			
			return new URL( getBaseUrl() + personByIdUrlFragment + "?" + "id=" + URLEncoder.encode(id, "utf-8") );

			
		} catch (MalformedURLException e) {			
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} catch (UnsupportedEncodingException e) {
			Log.e("ConnectInformation: ", e.getStackTrace().toString() );
		} 
		
		
		return null;
		
		
	}



	/**
	 * @return the baseUrl
	 */
	public String getBaseUrl() {
		return baseUrl;
	}



	
	
	
}
